package com.dunshanasync.service;

import lombok.extern.log4j.Log4j2;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

/**
 * @description: 异步请求
 * @author: 李文
 * @create: 2021-05-08 20:35
 **/
@Log4j2
@Async
@Component
public class AsyncService {


    public void asyncQuery(String data) {
        long startTime = System.currentTimeMillis();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        log.info("请求数据：{},开始时间是{}", data, sdf.format(new Date()));
        sleep(5000L);
        long endTime = System.currentTimeMillis();
        log.info("一共使用多长时间{}", (endTime - startTime));
        log.info("请求数据：{},结束时间是{}", data, sdf.format(new Date()));
    }

    public void sleep(long l) {
        try {
            Thread.sleep(l);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

